function examGrid()
{
    $('#examGrid').jqGrid({
                url: siteUrl + 'score/get_exams',
                mtype: 'post',
                datatype: 'json',
                postData: {
                  group_id: $('#group_id').val()
                },
                colNames: ['ID','Exam name', 'Group', 'Exam' , 'Date Posted' , 'Status', 'Operations'],
                colModel: [
                {name: 'exam_id', index: 'exam_id', hidden: true, key: true},
                {name: 'exam_name', index: 'exam_name'},
                {name: 'groups_group_id', index: 'groups_group_id', hidden: true},
                {name: 'exam_kind', index: 'exam_kind', hidden: false},
                {name: 'date_posted', index: 'date_posted', hidden: false},
                {name: 'status', index: 'status', hidden: false},
                {name: 'ops', index: 'ops', align: 'center', sortable: false, formatter: examOperations}
                ],
            autowidth: true,
            height: '200',
            pager: $('#pagination'),
            sortname: 'exam_id',
            sortorder: 'asc',
            viewrecords: true,
            rownumbers: true
    });
}

function examMyScoreGrid()
{
    $('#examMyScoreGrid').jqGrid({
                url: siteUrl + 'score/get_my_score',
                mtype: 'post',
                datatype: 'json',
                postData: {
                  group_id: $('#group_id').val()
                },
                colNames: ['ID','score_id', 'Exam Name', 'Score' , 'Total' , 'Exam Taken?','Date Posted', 'Operations'],
                colModel: [
                {name: 'exam_id', index: 'exam_id', hidden: true, key: true},
                {name: 'score_id', index: 'score_id', hidden: true},
                {name: 'exam_name', index: 'exam_name'},
                {name: 'actual_score', index: 'actual_score',  align: 'center'},
                {name: 'no_of_terms', index: 'no_of_terms', align: 'center', sortable: false},
                {name: 'is_exam_taken', index: 'is_exam_taken'},
                {name: 'date_posted', index: 'date_posted'},
                {name: 'ops', index: 'ops', align: 'center', sortable: false, formatter: examMyScoreOperations}
                ],
            autowidth: true,
            height: '200',
            pager: $('#pagination'),
            sortname: 'actual_score',
            sortorder: 'desc',
            viewrecords: true,
            rownumbers: true
    });
}

function examStudentScoreGrid()
{
    $('#examStudentScoreGrid').jqGrid({
                url: siteUrl + 'score/get_exam_student_score',
                mtype: 'post',
                datatype: 'json',
                postData: {
                  exam_id: $('#exam_id').val()
                },
                colNames: ['ID','score_id', 'exam_id', 'Student Name', 'Score' , 'Total' , 'Exam Taken?', 'Operations'],
                colModel: [
                {name: 'user_id', index: 'user_id', hidden: true, key: true},
                {name: 'score_id', index: 'score_id', hidden: true, key: false},
                {name: 'exam_id', index: 'exam_id', hidden: true, key: false},
                {name: 'student_name', index: 'student_name'},
                {name: 'actual_score', index: 'actual_score',  align: 'center'},
                {name: 'no_of_terms', index: 'no_of_terms', align: 'center', sortable: false},
                {name: 'is_exam_taken', index: 'is_exam_taken'},
                {name: 'ops', index: 'ops', align: 'center', sortable: false, formatter: examStudentScoreOperations}
                ],
            autowidth: true,
            height: '200',
            pager: $('#pagination'),
            sortname: 'actual_score',
            sortorder: 'desc',
            viewrecords: true,
            rownumbers: true
    });
}

function examOperations(cell, opts, rowObj)
{
    var id = opts.rowId;
    var group_id = rowObj[2];
    
    var student_score = '<a href="' + siteUrl + 'score/view_score/' + group_id + '/' + id + '" title="View Students Score" class="icon24 icon-board"></a>';
    student_score = (user_type != 'instructor' ) ? '<span class = "icon24" ></span>' : student_score;
    
    return student_score;
}
function examStudentScoreOperations(cell, opts, rowObj)
{
    var id = opts.rowId;
    var score_id = rowObj[1];
    
    var view_details = '<a href="' + siteUrl + 'score/view_score_detail/' + score_id + '/" title="View Student Score Details" class="icon24 icon-board"></a>';
    view_details = (user_type != 'instructor' || score_id == '' ) ? '<span class = "icon24" ></span>' : view_details;

    return view_details;
}
function examMyScoreOperations(cell, opts, rowObj)
{
    var id = opts.rowId;
    var score_id = rowObj[1];

    var view_details = '<a href="' + siteUrl + 'score/view_myscore_detail/' + score_id + '/" title="View Score Details" class="icon24 icon-board"></a>';
    view_details = (user_type != 'student' || score_id == '' ) ? '<span class = "icon24" ></span>' : view_details;

    return view_details;
}

function filterExamScore(){

    $('#examStudentScoreGrid').setGridParam({
    postData:
        {
            search: $('#search').val()
        }
    }).trigger('reloadGrid');
}
function filterMyExamScore(){

    $('#examMyScoreGrid').setGridParam({
    postData:
        {
            search: $('#search').val()
        }
    }).trigger('reloadGrid');
}